class_name PlayerJump
extends NodeState

@export var player: Player


var height := 0.0
var height_speed := 0.0


func _on_process(delta : float) -> void:
	process_air_time(delta)
	process_movement()



func _on_physics_process(_delta : float) -> void:
	pass


func _on_next_transitions() -> void:
	if height > 1.0 and player.inputManager.is_just_attack_input():
		transition_state(Player.STATE_JUMPKICK)




func _on_enter() -> void:
	height = 0.0
	height_speed = player.jump_intensity
	player.animationPlayer.play(Player.ANIMATION_JUMP)



func _on_exit() -> void:
	pass



func process_movement():
	var direction = player.inputManager.movement_input()
	player.velocity = direction * player.speed
	player.move_and_slide()


func process_air_time(delta: float):
	player.characterSprite.position = Vector2.UP * height

	height += height_speed * delta
	if height < 0.0:
		height = 0.0
		transition_state(Player.STATE_LAND)
	else:
		height_speed -= player.gravity * delta
